from flask import Flask, render_template, request, redirect, url_for, session
from flask_login import login_required
from models import db, User, Tag  # 假设你有User和Tag模型

app = Flask(__name__)

# 其他路由和视图函数...

@app.route('/user-query', methods=['GET', 'POST'])
@login_required
def user_query():
    if request.method == 'POST':
        selected_tags = request.form.getlist('tags')
        username = request.form.get('username')
        
        # 查询具有所选标签的用户
        query = User.query
        if selected_tags:
            query = query.join(User.tags).filter(Tag.name.in_(selected_tags))
        if username:
            query = query.filter(User.username.like(f'%{username}%'))
        
        users = query.all()
        return render_template('user_query.html', users=users)

    tags = Tag.query.all()  # 获取所有标签
    return render_template('user_query.html', tags=tags)

# 其他路由和视图函数...

if __name__ == '__main__':
    app.run(debug=True)